

<template>
  <div class="wish-login-layout">
    <div class="wish-login-wrap">
      <div class="wish-login-form-title">
        <span class="wish-login-form-title-span">Wish Web login</span>
      </div>
      <form class="wish-login-form validate-form">
        <!-- 用户名 -->
        <div class="wrap-input validate-input m-b-26">
          <span class="label-input">用户名</span>
          <input
            class="input"
            type="text"
            name="username"
            v-model="loginForm.account"
            placeholder="请输入用户名(demo)"
          />
          <span class="focus-input"></span>
        </div>
        <!-- 密码 -->
        <div class="wrap-input validate-input m-b-18">
          <span class="label-input">密码</span>
          <input
            class="input"
            type="password"
            name="username"
            v-model="loginForm.password"
            placeholder="请输入密码(123456)"
          />
          <span class="focus-input"></span>
        </div>
        <!-- 登录 -->
        <div class="wish-login-form-footer">
          <button class="wish-login-form-btn" @click.prevent="login">登 录</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
import { useStore } from '/@/store'
import { useRoute, useRouter } from 'vue-router'
import { urlToMap } from '/@/kit/common-kit'
import { isBlankForString, notBlankForString } from '/@/kit/blank-kit'
import { LoginUser } from '/@/_types/user'
import { message } from 'ant-design-vue'

export default defineComponent({
  name: 'Login',
  setup() {
    const store = useStore()
    const router = useRouter()
    const currentRoute = useRoute()
    const loginForm: LoginUser = reactive({
      account: null,
      password: null,
    })

    //登录
    const login = () => {
      if (isBlankForString(loginForm.account)) {
        message.warn('请输入账号')
        return false
      }
      if (isBlankForString(loginForm.password)) {
        message.warn('请输入密码')
        return false
      }
      store.dispatch('user/login', loginForm).then((res) => {
        let redirect = currentRoute.query.redirect ? String(currentRoute.query.redirect) : null
        //跳转首页
        if (notBlankForString(redirect)) {
          let len = redirect.indexOf('?')
          if (len != -1) {
            router.push({
              path: redirect.substring(0, len),
              query: urlToMap(redirect),
            })
          } else {
            router.push({ path: redirect })
          }
        } else {
          router.push({ path: '/' })
        }
      })
    }
    return {
      loginForm,
      login,
    }
  },
})
</script>

<style lang="less" scoped>
input:focus {
  border-color: transparent !important;
}

input:focus::-webkit-input-placeholder {
  color: transparent;
}

input:focus:-moz-placeholder {
  color: transparent;
}

input:focus::-moz-placeholder {
  color: transparent;
}

input:focus:-ms-input-placeholder {
  color: transparent;
}

input::-webkit-input-placeholder {
  color: #999999;
}

input:-moz-placeholder {
  color: #999999;
}

input::-moz-placeholder {
  color: #999999;
}

input:-ms-input-placeholder {
  color: #999999;
}

a:focus {
  outline: none !important;
}

a:hover {
  text-decoration: none;
  color: #57b846;
}

.wish-login-layout {
  width: 100%;
  min-height: 100vh;
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 15px;
  background: #ebeeef;
}

.wish-login-wrap {
  width: 670px;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.wish-login-form-title {
  width: 100%;
  position: relative;
  z-index: 1;
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  padding: 70px 15px 74px 15px;
  background-image: url('/@/assets/images/login.jpg');
}

.wish-login-form-title::before {
  content: '';
  display: block;
  position: absolute;
  z-index: -1;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: rgba(54, 84, 99, 0.7);
}

.wish-login-form-title-span {
  font-family: Poppins-Bold;
  font-size: 30px;
  color: #fff;
  text-transform: uppercase;
  line-height: 1.2;
  text-align: center;
}

.wish-login-form {
  width: 100%;
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 43px 88px 93px 190px;
}

.validate-input {
  position: relative;
}

.wrap-input {
  width: 100%;
  position: relative;
  border-bottom: 1px solid #b2b2b2;
}
.m-b-26 {
  margin-bottom: 26px;
}

.m-b-18 {
  margin-bottom: 18px;
}

.label-input {
  font-family: Poppins-Regular;
  font-size: 15px;
  color: #808080;
  line-height: 1.2;
  text-align: right;
  position: absolute;
  top: 14px;
  left: -105px;
  width: 80px;
}

input.input {
  height: 45px;
}
.input {
  font-family: Poppins-Regular;
  font-size: 15px;
  color: #555555;
  line-height: 1.2;
  display: block;
  width: 100%;
  background: transparent;
  padding: 0 5px;
}
input {
  outline: none;
  border: none;
}

.focus-input {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}

.wish-login-form-footer {
  width: 100%;
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
}

.wish-login-form-btn {
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  min-width: 160px;
  height: 50px;
  background-color: #57b846;
  border-radius: 25px;
  font-family: Poppins-Regular;
  font-size: 16px;
  color: #fff;
  line-height: 1.2;
  -webkit-transition: all 0.4s;
  -o-transition: all 0.4s;
  -moz-transition: all 0.4s;
  transition: all 0.4s;
}

button {
  outline: none !important;
  border: none;
  background: transparent;
}

.wish-login-form-btn:hover {
  cursor: pointer;
  background-color: #333333;
}

@media (max-width: 576px) {
  .wish-login-form {
    padding: 43px 15px 57px 117px !important;
  }
}

@media (max-width: 480px) {
  .wish-login-form {
    padding: 43px 15px 57px 15px !important;
  }
  .label-input {
    text-align: left;
    position: unset;
    top: unset;
    left: unset;
    width: 100%;
    padding: 0 5px;
  }
}
</style>